﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Net;
using System.IO;
using System.Text;

public class testNet : MonoBehaviour {
  /*  public  Text text;

	// Use this for initialization
    private Button btn;
    string content;
    void Awake() 
    {
        btn = GetComponent<Button>();
        btn.onClick.AddListener(Click);

      //  btn.onClick.AddListener(POSTClick);
        
    }
    void Click() 
    {
        WebRequest req = HttpWebRequest.Create("http://112.74.26.66:8899/");
       req.Method = "GET";
       req.BeginGetResponse(ResponseCallBack, req);
       print("baidu请求");
    }
    
    



    void POSTClick() 
    {
        WebRequest req = HttpWebRequest.Create("http://112.74.26.66:8899/");
        req.Method = "POST";
        req.BeginGetRequestStream(PostResponseCallBack,req);
        print("post请求");
    }
    private void PostResponseCallBack(System.IAsyncResult result)
    {
        print("baidu回应");
        HttpWebRequest hwq = (HttpWebRequest)result.AsyncState;
        Stream webRespomse = hwq.EndGetRequestStream(result);
        string postString = "fkfmg|大罗哥哥|66";
        byte[] date = Encoding.UTF8.GetBytes(postString);
        webRespomse.Write(date, 0, date.Length);
        webRespomse.Close();
        hwq.BeginGetResponse(ResponseCallBack, hwq);
    }
    private void ResponseCallBack(System.IAsyncResult result)
    {
        print("baidu回应");
        HttpWebRequest hwq = (HttpWebRequest)result.AsyncState;
        WebResponse webRespomse = hwq.EndGetResponse(result);
        Stream strem = webRespomse.GetResponseStream();
        StreamReader reader = new StreamReader(strem);
        content = reader.ReadToEnd();

    }

















    void Update() 
    {
        text.text = content;
    }*/
}
